package vip.xiaonuo.biz.modular.article.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.biz.modular.article.entity.BizArticle;
import vip.xiaonuo.biz.modular.article.param.BizArticleAddParam;
import vip.xiaonuo.biz.modular.article.param.BizArticleEditParam;
import vip.xiaonuo.biz.modular.article.param.BizArticleIdParam;
import vip.xiaonuo.biz.modular.article.param.BizArticlePageParam;
import vip.xiaonuo.biz.modular.article.service.BizArticleService;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.common.pojo.CommonValidList;
import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@RequestMapping("/biz/article")
@Validated
@RestController
public class BizArticleController {


    @Resource
    private BizArticleService service;


    @CommonLog("新增文章")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody BizArticleAddParam addParam){
        service.add(addParam);
        return CommonResult.ok();
    }

    @CommonLog("编辑文章")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody BizArticleEditParam editParam){
        service.edit(editParam);
        return CommonResult.ok();
    }

    @CommonLog("删除文章")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @NotEmpty(message = "id列表不能为空") CommonValidList<BizArticleIdParam> idListParam){
        service.delete(idListParam);
        return CommonResult.ok();
    }

    @GetMapping("/page")
    public CommonResult<Page<BizArticle>> page(BizArticlePageParam pageParam){
        return CommonResult.data(service.page(pageParam));
    }

    @GetMapping("/detail")
    public CommonResult<BizArticle> detail(BizArticleIdParam idParam){
        return CommonResult.data(service.detail(idParam));
    }

    @GetMapping("/getLatestArticle")
    public CommonResult<List<BizArticle>> getLatestArticle(){
        return CommonResult.data(service.getLatestArticle());
    }

    @PostMapping("/editVisible")
    public CommonResult<String> editVisible(@RequestBody BizArticleEditParam editParam){
        service.editVisible(editParam);
        return CommonResult.ok();
    }
}
